#!/bin/sh

# 部署目录
APP_DIR="/opt/app"
# 应用名称
APP_NAME="teddy"
# 应用版本
APP_VERSION="0.0.1-SNAPSHOT"
# JAR 文件名
JAR_NAME="$APP_NAME-$APP_VERSION.jar"
# 备份目录
BACKUP_DIR="$APP_DIR/backup"
# 日志文件
LOG_FILE="$APP_DIR/$APP_NAME.log"

# 停止正在运行的旧版本应用
echo "Stopping old application..."
pid=$(ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}')
if [ -n "$pid" ]; then
  kill -9 $pid
  echo "Application stopped."
else
  echo "No running application found."
fi

# 启动新版本应用
echo "Starting new application..."
JAVA_OPTS="-server -Xms2g -Xmx2g -Xmn256m -Xss256k -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled"
nohup java $JAVA_OPTS -jar $JAR_NAME &

echo "Deployment completed."